﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace c2
{
    public delegate void event_handler(object sender);
    internal class Alarm
    {
        private int hour;
        private int minute;
        private int second;

        public event event_handler alarm_timeup_event;
        public event event_handler alarm_ticktack;
        public Alarm(int hour,int minute,int second=0) { this.hour = hour; this.minute = minute; this.second = second;  }
        public Alarm() { this.hour = 0;this.minute = 0;this.second = 0;  }
        internal void setClock(int hour,int minute,int second=0) { this.hour = hour;this.minute = minute;this.second = second; }
        
        public void start()
        {
            Event_subscriber a = new Event_subscriber();
            alarm_timeup_event += a.alarm_triggered;
            alarm_ticktack += a.tick_tack;
            int left = hour * 3600 + minute * 60 + second;
            for (; left > 10; left--)
            {
                System.Threading.Thread.Sleep(1000);
            }

            for (; left > 0; left--)
            {
                alarm_ticktack(this);
                System.Threading.Thread.Sleep(1000);
            }
            alarm_timeup_event(this);
            System.Threading.Thread.Sleep(1000);
        }

        
        

    }

    internal class Event_subscriber
    {
        public Event_subscriber()
        {
        }
        private bool tick_tack_flag = true;
        public void alarm_triggered(object sender) { Console.WriteLine("Time up，Alarm Triggered! Ring!!!!!"); }
        public void tick_tack(object sender) { if (tick_tack_flag) { Console.WriteLine("Tick"); } else { Console.WriteLine("Tack"); } tick_tack_flag = !tick_tack_flag; }

    }
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("please enter the time(HH:MM:SS)");
            String c=Console.ReadLine();
            String[] clist=c.Split(':');
            int[] list=new int[3];
            for(int i = 0; i < 3; i++) { list[i] = Convert.ToInt32(clist[i]); }
            Alarm test = new Alarm(list[0], list[1], list[2]);
            Console.WriteLine("The Alarm will ring after " + list[0] + "h " + list[1] + "m " + list[2] + "s.");
            test.start();
        }
    }
}
